
window.onload = () => {
    func.sound.checkSelect_voice()
    func.sound.checkSelect_insulation()
    func.light.select_event()
    func.light.appendToList(0, Object.keys(standrad.light.data))
    $("#building-0").trigger("change")
    func.heat.checkSelect_type()

    $("#submit-house-result").on("click", () => {

        // let score = {}
        // score.sound = {
        //     voice: engine.sound_voice(),
        //     insulation: engine.sound_insulation()
        // }
        // let light_input_items = $(".light-input")
        // let light_params = {}
        // for (let index = 0; index < light_input_items.length; index++) {
        //     if ($(light_input_items[index]).css("display") != "none") {
        //         let tmp_el = light_input_items[index]
        //         let tmp_params = ""
        //         tmp_params += "['" + $(tmp_el).find("label").attr("value") + "']"
        //         // 如果该选项下还有下拉框
        //         let tmp_sel = $(tmp_el).find("select")
        //         if (tmp_sel.length > 0) {
        //             tmp_params += "['" + $(tmp_sel).val() + "']"
        //         }
        //         light_params[tmp_params] = $(tmp_el).find("input").val()
        //     }
        // }
        // score.light = engine.light(func.light.getPath(), light_params)

        // let heat_type = {}
        // let heat_params = {}
        // let tmp = $("#heat").val()
        // heat_type.env = "人工冷热源热环境"
        // if(tmp == 0){
        //     heat_type.whole = "整体评价"
        // }else if(tmp == 1){
        //     heat_type.whole = "局部评价"
        // }else if(tmp ==2){
        //     heat_type.env = "非人工冷热源热环境"
        // }
        
        // let heat_input_items = $(".heat .heat-input")
        // for (let index = 0; index < heat_input_items.length; index++) {
        //     if ($(heat_input_items[index]).css("display") != "none") {
        //         let tmp_el = heat_input_items[index]
        //         let label = $(tmp_el).find("label").attr("value")
        //         if(label=="building" || label=="region"){
        //             heat_params[label] = $(tmp_el).find("select").val()
        //         }else{
        //             heat_params[label] = $(tmp_el).find("input").val()
        //         }
                
        //     }
        // }
        // score.heat = engine.heat.grade(heat_type, heat_params)


        // let air_input_items = $(".air .air-input")
        // let air_params = {}
        // for (let index = 0; index < air_input_items.length; index++) {
        //     let tmp_el = air_input_items[index]
        //     air_params[$(tmp_el).find("label").attr("value")] = $(tmp_el).find("input").val()
        // }
        // score.air = engine.air(air_params)

        // ques_nums = $(".ques").length
        // ques_ans = {}
        // for(let i=0;i<ques_nums;i++){

        // }
 



    })

}


let func = {
    sound: {
        checkSelect_voice: () => {
            $("#sound-build-sel-list_voice select").on("change", function () {
                var values_sound1 = $("#sound1 option:selected").val();

                if (values_sound1 == 0) {
                    $('#option2').hide();
                    $('#option1').show();
                }
                else {
                    $('#option1').hide();
                    $('#option2').show();

                }
            })
        },
        checkSelect_insulation: () => {
            $("#sound-build-sel-list_insulation select").on("change", function () {
                var values_sound2 = $("#sound2 option:selected").val();
                console.log(values_sound2)

                if (values_sound2 == 0) {
                    $('#parameter3').hide();
                    $('#parameter4').hide();
                    $('#parameter5').hide();
                    $('#parameter1').show();
                    $('#parameter2').show();
                }
                else if (values_sound2 == 1) {
                    $('#parameter2').hide();
                    $('#parameter4').hide();
                    $('#parameter5').hide();
                    $('#parameter1').show();
                    $('#parameter3').show();
                }
                else if (values_sound2 == 2) {
                    $('#parameter1').hide();
                    $('#parameter3').hide();
                    $('#parameter5').hide();
                    $('#parameter4').show();
                    $('#parameter2').show();
                }
                else {
                    $('#parameter2').hide();
                    $('#parameter4').hide();
                    $('#parameter3').hide();
                    $('#parameter1').hide();
                    $('#parameter5').show();
                }
            })
        }
    },
    light: {
        getPath: (stop_series) => {
            // 获取当前选项
            // 首先判断有多少个选项
            let bop = $(".light-build-sel-op")
            let b_count = 0
            for (let index = 0; index < bop.length; index++) {
                if ($(bop[index]).css("display") != "none") {
                    b_count++
                }
            }
            if (stop_series != undefined && stop_series < b_count) {
                b_count = stop_series
            }
            let path = []
            for (let index = 0; index < b_count; index++) {
                path.push($("#building-" + index).val())
            }
            return path

        },
        select_event: () => {
            $("#light-build-sel-list select").on("change", function (event) {
                let b_type = $("#building-0").val()
                if (b_type == "无电视转播的体育建筑") {
                    $("#light-lx-sel select").empty()
                    let op_lx = ["训练和娱乐", "业余比赛", "专业比赛"]
                    for (let i = 0; i < op_lx.length; i++) {
                        $("#light-lx-sel select").append("<option>" + op_lx[i] + "</option>")
                    }
                    $("#light-lx-sel").show()

                    $("#light-Ra-sel select").empty()
                    let op_Ra = ["训练", "比赛"]
                    for (let i = 0; i < op_Ra.length; i++) {
                        $("#light-Ra-sel select").append("<option>" + op_Ra[i] + "</option>")
                    }
                    $("#light-Ra-sel").show()

                    $("#light-GR-sel select").empty()
                    let op_GR = ["训练", "比赛"]
                    for (let i = 0; i < op_GR.length; i++) {
                        $("#light-GR-sel select").append("<option>" + op_GR[i] + "</option>")
                    }
                    $("#light-GR-sel").show()

                    $("#light-K").hide()
                    $("#light-UGR").hide()
                    $("#light-U0").hide()
                    $("#light-R9").hide()


                } else if (b_type == "有电视转播的体育建筑") {
                    $("#light-lx-sel select").empty()
                    let op = ["国家、国际比赛", "重大国际比赛", "HDTV"]
                    for (let i = 0; i < op.length; i++) {
                        $("#light-lx-sel select").append("<option>" + op[i] + "</option>")
                    }
                    $("#light-lx-sel").show()

                    $("#light-Ra-sel select").empty()
                    let op_Ra = ["国家、国际比赛,重大国际比赛", "HDTV"]
                    for (let i = 0; i < op_Ra.length; i++) {
                        $("#light-Ra-sel select").append("<option>" + op_Ra[i] + "</option>")
                    }
                    $("#light-Ra-sel").show()

                    $("#light-K-sel select").empty()
                    let op_K = ["国家、国际比赛,重大国际比赛", "HDTV"]
                    for (let i = 0; i < op_K.length; i++) {
                        $("#light-K-sel select").append("<option>" + op_K[i] + "</option>")
                    }
                    $("#light-K").show()
                    $("#light-GR").show()
                    $("#light-GR-sel").hide()
                    $("#light-UGR").hide()
                    $("#light-U0").hide()
                    $("#light-R9").hide()

                } else if (b_type == "教育建筑") {

                    $("#light-lx").show()
                    $("#light-lx-sel").hide()
                    $("#light-UGR").show()
                    $("#light-U0").show()
                    $("#light-Ra").show()
                    $("#light-Ra-sel").hide()
                    $("#light-R9").show()
                    $("#light-GR").hide()
                    $("#light-K").hide()


                } else {
                    $("#light-lx").show()
                    $("#light-Ra").show()
                    $("#light-GR").show()
                    $("#light-lx-sel").hide()
                    $("#light-Ra-sel").hide()
                    $("#light-GR-sel").hide()
                    $("#light-UGR").hide()
                    $("#light-U0").hide()
                    $("#light-R9").hide()
                    $("#light-K").hide()
                }

                let el_series = parseInt($(event.target).attr("val"))

                for (let index = el_series + 1; index <= 5; index++) {
                    let p = $("#building-" + index)
                    $(p).hide()

                }
                nextMenu = func.light.getMenu($(event.target).attr("val"))
                console.log(nextMenu)
                // 如果还有下级菜单
                if (nextMenu) {
                    $("#building-" + (el_series + 1)).show()
                    func.light.appendToList(el_series + 1, nextMenu)
                }
            })
        },
        getMenu: (sel_series) => {
            // 当前选择建筑的序列号

            let path = func.light.getPath(sel_series + 1)
            let tmp = standrad.light.data[path[0]]

            for (let index = 1; index < path.length; index++) {
                tmp = tmp[path[index]]
            }

            if (tmp.constructor == Array) {
                return false
            } else {
                let menu = []
                for (let key in tmp) {
                    menu.push(key)
                }
                return menu
            }

        },
        appendToList: (series, build_name_list) => {
            let el = document.getElementById("building-" + series)
            // 清空之前的选项
            $(el).empty()
            for (var i = 0; i < build_name_list.length; i++) {
                new_item = document.createElement("option")
                new_item.innerHTML = build_name_list[i]
                document.getElementById("building-" + series).appendChild(new_item)
            }
        }

    },

    heat: {
        checkSelect_type: () => {
            $("#heat-sel-list select").on("change", function () {
                var values_heat = $("#heat option:selected").val();

                if (values_heat == 0) {
                    $('.heat_artificial_local').hide();
                    $('.heat_unartificial').hide();
                    $('#heat_artificial_total').show();
                }
                else if (values_heat == 1) {

                    $('.heat_artificial_local').show();
                    $('.heat_unartificial').hide();
                    $('#heat_artificial_total').hide();

                } else {
                    $('.heat_artificial_local').hide();
                    $('.heat_unartificial').show();
                    $('#heat_artificial_total').show();
                }
            })
        }
    }

}